// __PUBLIC__/js/page/admin/content/comment
require(['../../common'], function() {
  require(['content.comment'])
})

define('content.comment', [
  'jquery',
  'page/grid'
], function($, Grid) {
  'use strict';

  var $table = $('.table')
  var mygrid = new Grid($table)
  mygrid.init()

  function getSelected() {
    var selected = mygrid.getSelected()
    if (!selected.count) {
      alert(lang.pleaseSelectAData)
      return
    }
    return selected
  }

  function getASelected(t) {
    var current = mygrid.getCurrent(t)
    var selected = {
      id: [current.id],
      index: [current.index]
    }
    return selected
  }

  $(document)
    .on('click', '.A_del', function(e) {
      e.preventDefault()
      deleteComment(getASelected(this))
    })
    .on('click', '#J_del', function(e) {
      e.preventDefault()
      deleteComment(getSelected())
    })

  function deleteComment(selected) {
    var from_app = $('#from_app').val()
    $.post(APP + '?app=admin&m=Content&a=deleteComment', {
      ids: selected.id.join(),
      from_app: from_app
    }).done(function(res) {
      if (res == '1') {
        alert(lang.delSuccess)
        mygrid.del(selected.index)
      } else {
        alert(lang.delFails)
      }
    })
  }

})
